from django.db import models
from berlin.metadata.models import AttributeType, PersonType, PersonAttribute, GroupType, GroupAttribute, EventType, EventAttribute
# Create your models here.

class Person(models.Model):
    name = models.TextField()
    type = models.ForeignKey(PersonType)
    groups = models.ManyToManyField('Group', null=True, blank=True)
    events = models.ManyToManyField('Event', null=True, blank=True)
    
    def __unicode__(self):
        return (self.name + u'[' + unicode(self.pk) + u']')

class PersonParameter(models.Model):
    person = models.ForeignKey(Person)
    attribute = models.ForeignKey(PersonAttribute)
    value = models.TextField() 
    
    def __unicode__(self):
        return (self.person.name + '.' + self.attribute.name + ' : ' + self.value)

class Group(models.Model):
    name = models.TextField()
    type = models.ForeignKey(GroupType)
    persons = models.ManyToManyField('Person', null=True, blank=True)
    events = models.ManyToManyField('Event', null=True, blank=True)
    
    def __unicode__(self):
        return (self.name + u'[' + unicode(self.pk) + u']')


class GroupParameter(models.Model):
    group = models.ForeignKey(Group)
    attribute = models.ForeignKey(GroupAttribute)
    value = models.TextField() 
    
    def __unicode__(self):
        return (self.name + u'[' + unicode(self.pk) + u']')


class Event(models.Model):
    name = models.TextField()
    type = models.ForeignKey(EventType)
    persons = models.ManyToManyField(Person, null=True, blank=True)
    groups = models.ManyToManyField(Group, null=True, blank=True) 
    
    def __unicode__(self):
        return (self.name + u'[' + unicode(self.pk) + u']')


class EventParameter(models.Model):
    event  = models.ForeignKey(Event)
    attribute = models.ForeignKey(EventAttribute)
    value = models.TextField() 
    
    def __unicode__(self):
        return (self.name + u'[' + unicode(self.pk) + u']')
    

class PersonArtifact(models.Model):
    '''
    Artifact - result of person being at event
    '''
    person = models.ForeignKey(Person)
    event = models.ForeignKey(Event)
    type = models.ForeignKey(AttributeType)
    value = models.TextField(blank=True)


class GroupArtifact(models.Model):
    group = models.ForeignKey(Group)
    event = models.ForeignKey(Event)
    type = models.ForeignKey(AttributeType)
    value = models.TextField(blank=True)
    